//
// Created by zhupi on 2024/11/13.
//

#ifndef DEMO2_EXPORT_PROJECT_H
#define DEMO2_EXPORT_PROJECT_H

#include <QDialog>
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <QLineEdit>

class ExportAedtDialog : public QDialog
{
    Q_OBJECT
public:
    explicit ExportAedtDialog(QWidget *parent) {
    setWindowTitle("导出.aedt文件");

    QVBoxLayout *layout = new QVBoxLayout(this);

    pathLineEdit = new QLineEdit(this);
    pathLineEdit->setPlaceholderText("选择导出.aedt文件的路径...");
    pathLineEdit->setReadOnly(true);  // 设置为只读
    layout->addWidget(pathLineEdit);

    QPushButton *browseButton = new QPushButton("浏览", this);
    connect(browseButton, &QPushButton::clicked, this, &ExportAedtDialog::browseFile);
    layout->addWidget(browseButton);

    QPushButton *exportButton = new QPushButton("导出", this);
    connect(exportButton, &QPushButton::clicked, this, &ExportAedtDialog::exportFile);
    layout->addWidget(exportButton);

    setLayout(layout);
}

private slots:
void browseFile() {
    QString filePath = QFileDialog::getSaveFileName(this, "选择导出.aedt文件路径", "", "AEDT Files (*.aedt)");
    if (!filePath.isEmpty()) {
        if (!filePath.endsWith(".aedt")) {
            filePath += ".aedt";  // 确保文件名以.aedt结尾
        }
        pathLineEdit->setText(filePath);
    }
}

void exportFile() {
    QString filePath = pathLineEdit->text();
    if (filePath.isEmpty()) {
        QMessageBox::warning(this, "警告", "请先选择导出.aedt文件的路径！");
    } else {
        // 在这里添加导出文件的逻辑
        QMessageBox::information(this, "导出成功", "成功导出到: " + filePath);
    }
}

private:
QLineEdit *pathLineEdit;
};
#endif //DEMO2_EXPORT_PROJECT_H
